﻿package cn.com.exlibris.util;

/**
 * <p>Title:系统基本函数 </p>
 * <p>Description:系统基本函数在该类中 </p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: exl_cn</p>
 * @author airboat
 * @version 1.0
 */
import java.io.*;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.log4j.Logger;
import java.net.*;

import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;

import org.dom4j.*;

import cn.com.exlibris.db.MyDBManager;

/**
 * 系统基本函数在该类中,如字符编码转换函数，字符串处理函数
 * 
 */
public class Func2 {

	private final static Logger logger = Logger.getLogger(Func2.class);
	private MyDBManager MyDBManagerBean = new MyDBManager();

	public Func2() {
	}

	public void error(String errorMsg) {
		logger.error(errorMsg);
	}

	public void info(String infoMsg) {
		logger.info(infoMsg);
	}

	// ***************************************************************************
	/**
	 * 字段的判空处理 新增对Html特殊字符的处理
	 * 
	 * @param argString
	 *          String
	 * @return
	 */
	// ***************************************************************************
	public String getDisplayString(String argString) {
		if (argString == null) {
			return "";
		} else {
			argString = argString.trim();
			argString = changeToHtml(argString);
			return argString;
		}
	}

	public String getDisplayString(Object argString) {
		if (argString == null) {
			return "";
		} else {
			String returnStr = null;
			returnStr = argString.toString();
			returnStr = returnStr.trim();
			returnStr = changeToHtml(returnStr);
			return returnStr;
		}
	}

	public String getDisplayString(Object argString, boolean trim) {
		if (argString == null) {
			return "";
		} else {
			String returnStr = null;
			returnStr = argString.toString();
			if (trim == true) {
				returnStr = returnStr.trim();
			}
			return returnStr;
		}
	}

	public String getDisplayString(Object argString, boolean trim, boolean html) {
		if (argString == null) {
			return "";
		} else {
			String returnStr = null;
			returnStr = argString.toString();
			if (trim == true) {
				returnStr = returnStr.trim();
			}

			if (html == true) {
				returnStr = changeToHtml(returnStr);
			}
			return returnStr;
		}
	}

	// 如果字串稍小一点，不发生错误，chageToHtml()所用时间比transform()要少得多
	public String changeToHtml(String input) {
		if (input == null || input.length() == 0) {
			return "";
		}
		char c = ' ';
		StringBuffer sb = new StringBuffer(input.length());

		for (int i = 0; i < input.length(); i++) {
			c = input.charAt(i);
			// if (c == ' ') {
			// sb.append("&nbsp;");
			// continue;
			// }
			if (c == '<') {
				sb.append("&lt;");
				continue;
			}
			if (c == '>') {
				sb.append("&gt;");
				continue;
			}
			// if (c == '\n') {
			// sb.append("<br> ");
			// continue;
			// }
			if (c == '&') {
				sb.append("&amp;");
				continue;
			}
			if (c == '\'') {
				sb.append("’"); // 全角
				continue;

			} else {
				sb.append(c);
			}

		}
		return sb.toString();
	}

	// 作用同上，但排除 空格 和 换行，用作文本框显示
	public String encodeTextBox(String s) {
		s = s.replaceAll("&", "&amp;");
		s = s.replaceAll("<", "&lt;");

		s = s.replaceAll(">", "&gt;");
		// s = s.replaceAll("′","'");

		return s;
	}

	// 作用同上，但排除 空格 和 换行，用作文本框显示
	public String getDisplayRule(String s) {
		s = ADD_BLANK_TO_STRING(s, 180);
		String return_str = "";
		String tmp01 = "";
		String tmp02 = "";
		String tmp03 = "";
		String tmp04 = "";
		for (int i = 0; (i + 18) <= s.length(); i = i + 18) {
			if (!s.substring(i, i + 18).trim().equals("")) {
				tmp01 = s.substring(i, i + 6).trim() + ",";
				tmp02 = s.substring(i + 6, i + 12).trim() + ",";
				tmp03 = s.substring(i + 12, i + 15).trim() + ",";
				tmp04 = s.substring(i + 15, i + 18).trim() + ";";
				return_str += tmp01 + tmp02 + tmp03 + tmp04;
			}
		}

		return return_str;
	}

	/**
	 * 字符串替换函数
	 * 
	 * @param in
	 *          被替换的字符串
	 * @param from
	 *          被替换的子字符串
	 * @param to
	 *          被替换成的子字符串
	 * @return string 被替换后的字符串
	 */
	public String replaceInString(String in, String from, String to) {
		StringBuffer sb = new StringBuffer(in.length() * 2);
		String posString = in.toLowerCase();
		String cmpString = from.toLowerCase();
		int i = 0;
		for (boolean done = false; i < in.length() && !done;) {
			int start = posString.indexOf(cmpString, i);
			if (start == -1) {
				done = true;
			} else {
				sb.append(String.valueOf(in.substring(i, start)) + String.valueOf(to));
				i = start + from.length();
			}
		}

		if (i < in.length()) {
			sb.append(in.substring(i));
		}
		return sb.toString();
	}

	// 根据字节数来截取一个字符串的长度
	public String SubStringByte(String text, int beginIndex, int endIndex) {
		byte temp[];
		byte temp1[];
		String ReturnContent = "";
		try {
			temp = text.getBytes("GBK");
			if (temp.length < endIndex) {
				endIndex = temp.length;
			}
			temp1 = new byte[endIndex - beginIndex];

			for (int i = 0; i < endIndex - beginIndex; i++) {
				temp1[i] = temp[beginIndex + i];
			}
			ReturnContent += new String(temp1, "GBK");
		} catch (Exception e) {
			System.out.println(e.toString());
		}
		return ReturnContent;
	}

	// 根据字节数来截取一个字符串的长度
	public String SubStringByte(String text, int beginIndex, int endIndex, String byte_Type) {
		byte temp[];
		byte temp1[];
		String ReturnContent = "";
		try {
			temp = text.getBytes(byte_Type);
			if (temp.length < endIndex) {
				endIndex = temp.length;
			}
			temp1 = new byte[endIndex - beginIndex];
			for (int i = 0; i < endIndex - beginIndex; i++) {
				temp1[i] = temp[beginIndex + i];
			}
			ReturnContent += new String(temp1, byte_Type);
		} catch (Exception e) {
			System.out.println(e.toString());
		}

		return ReturnContent;
	}

	// 根据字节数来截取一个字符串的长度
	public String SubStringByte(String text, int beginIndex, String byte_Type) {
		byte temp[];
		byte temp1[];
		String ReturnContent = "";
		int endIndex = 0;
		try {
			temp = text.getBytes(byte_Type);
			endIndex = temp.length;
			temp1 = new byte[endIndex - beginIndex];

			for (int i = 0; i < endIndex - beginIndex; i++) {
				temp1[i] = temp[beginIndex + i];
			}
			ReturnContent += new String(temp1, byte_Type);
		} catch (Exception e) {
			System.out.println(e.toString());
		}

		return ReturnContent;
	}

	// 根据字节数来截取一个字符串的长度
	public String SubStringByte(String text, int beginIndex) {
		byte temp[];
		byte temp1[];
		String ReturnContent = "";
		int endIndex = 0;
		try {
			temp = text.getBytes("GBK");
			endIndex = temp.length;
			temp1 = new byte[endIndex - beginIndex];

			for (int i = 0; i < endIndex - beginIndex; i++) {
				temp1[i] = temp[beginIndex + i];
			}
			ReturnContent += new String(temp1, "GBK");
		} catch (Exception e) {
			System.out.println(e.toString());
		}

		return ReturnContent;
	}

	// 得到一个文件的内容
	public String GetFileContent(String FilePathName) {
		StringBuffer ReturnContent = new StringBuffer("");
		java.io.File ThisFile = new java.io.File(FilePathName);

		if (ThisFile.exists()) {
			try {
				// StringBuffer Readlinestr = new StringBuffer("");
				String Readlinestr = "";
				InputStreamReader read = new InputStreamReader(new FileInputStream(ThisFile), "GBK");
				BufferedReader br = new BufferedReader(read);
				// while ( (Readlinestr = new StringBuffer(br.readLine())) != null) {
				while ((Readlinestr = br.readLine()) != null) {
					ReturnContent.append(Readlinestr + "\n");
				}
				br.close();
				read.close();
			} catch (Exception e) {
				logger.error("Read File error:" + FilePathName + ". e.getMessage(): " + e.getMessage() + "\n");
			}
		}

		return ReturnContent.toString();
	}

	// 写一个文件的内容
	public boolean SetFileContent(String FilePathName, String FileContent) {
		boolean ReturnFlag = false;
		// 这是将一个字符串写入文件
		try {
			// 写入
			FileOutputStream fos = new FileOutputStream(FilePathName);
			Writer out1 = new OutputStreamWriter(fos, "GBK");
			out1.write(FileContent);

			out1.close();
			fos.close();
			ReturnFlag = true;

		} catch (Exception e) {
			System.err.println("Write File error! " + FilePathName);
		}
		return ReturnFlag;
	}

	// 写一个文件的内容
	public boolean SetFileContent(String FilePathName, String FileContent, String CharType) {
		boolean ReturnFlag = false;
		// 这是将一个字符串写入文件
		try {
			// 写入
			FileOutputStream fos = new FileOutputStream(FilePathName);
			Writer out1 = new OutputStreamWriter(fos, CharType);
			out1.write(FileContent);

			out1.close();
			fos.close();
			ReturnFlag = true;

		} catch (Exception e) {
			System.err.println("Write File error! " + FilePathName);
		}
		return ReturnFlag;
	}

	// 得到一个文件的内容
	public String GetFileContent(String FilePathName, String CharType) {
		StringBuffer ReturnContent = new StringBuffer("");
		java.io.File ThisFile = new java.io.File(FilePathName);

		if (ThisFile.exists()) {
			try {
				// StringBuffer Readlinestr = new StringBuffer("");
				String Readlinestr = "";
				InputStreamReader read = new InputStreamReader(new FileInputStream(ThisFile), CharType);
				BufferedReader br = new BufferedReader(read);
				while ((Readlinestr = br.readLine()) != null) {
					// while ((Readlinestr = new StringBuffer(br.readLine())) != null) {
					ReturnContent.append(Readlinestr + "\n");
				}
				br.close();
				read.close();
			} catch (Exception e) {
				logger.error("Read File error:" + FilePathName + ". e.getMessage(): " + e.getMessage() + "\n");
			}
		}

		return ReturnContent.toString();
	}

	// 得到一个文件的内容
	public String GetFileContent2(String FilePathName, String CharType) {
		StringBuffer ReturnContent = new StringBuffer("");
		java.io.File ThisFile = new java.io.File(FilePathName);

		if (ThisFile.exists()) {
			try {
				StringBuffer Readlinestr = new StringBuffer("");
				// String Readlinestr = "";
				InputStreamReader read = new InputStreamReader(new FileInputStream(ThisFile), CharType);
				BufferedReader br = new BufferedReader(read);
				// while ((Readlinestr = br.readLine()) != null) {
				while ((Readlinestr = new StringBuffer(br.readLine())) != null) {
					ReturnContent.append(Readlinestr + "\n");
				}
				br.close();
				read.close();
			} catch (Exception e) {
				logger.error("Read File error:" + FilePathName + ". e.getMessage(): " + e.getMessage() + "\n");
			}
		}

		return ReturnContent.toString();
	}

	public String readFileByBytes(String fileName) {
		StringBuffer ReturnContent = new StringBuffer("");

		File file = new File(fileName);
		InputStream in = null;
		try {
			System.out.println("以字节为单位读取文件内容，一次读一个字节：");
			// 一次读一个字节
			in = new FileInputStream(file);
			int tempbyte;
			while ((tempbyte = in.read()) != -1) {
				System.out.write(tempbyte);
				// ReturnContent.append((byte)tempbyte);

			}
			in.close();
		} catch (IOException e) {
			e.printStackTrace();

		}
		return ReturnContent.toString();
	}

	/**
	 * 以字符为单位读取文件，常用于读文本，数字等类型的文件
	 * 
	 * @param fileName
	 *          文件名
	 */
	public String readFileByChars(String fileName) {

		StringBuffer ReturnContent = new StringBuffer("");
		File file = new File(fileName);
		Reader reader = null;
		try {
			System.out.println("以字符为单位读取文件内容，一次读一个字节：");
			// 一次读一个字符
			reader = new InputStreamReader(new FileInputStream(file),"GBK");
			int tempchar;
			while ((tempchar = reader.read()) != -1) {
				// 对于windows下，rn这两个字符在一起时，表示一个换行。
				// 但如果这两个字符分开显示时，会换两次行。
				// 因此，屏蔽掉r，或者屏蔽n。否则，将会多出很多空行。
				if (((char) tempchar) != 'r') {
					System.out.print((char) tempchar);
					ReturnContent.append((char)tempchar);
				}
			}
			reader.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ReturnContent.toString();
	}

	// 执行命令程序
	public String ExeCommand(String CommandStr) {
		String ReturnString = "";
		logger.info("ExeCommand:" + CommandStr);
		try {
			Process child = Runtime.getRuntime().exec(CommandStr);
			BufferedReader in = new BufferedReader(new InputStreamReader(child.getInputStream()));
			String s;
			while ((s = in.readLine()) != null) {
				ReturnString += s + "<br>\n";
			}
		} catch (Exception e) {
			logger.error("ExeCommand Error: " + e.getMessage());
		}
		return ReturnString;
	}

	/**
	 * 该函数用于页面POST或GET中的参数.
	 * 
	 * @param Param
	 *          参数名称
	 * @return (string)参数值
	 */
	public static String getFixedParameter(String Param) {
		if (Param == null) {
			Param = "";
		} else {
			Param = Param.trim();
			Param = Func2.ISOtoUTF8(Param);
		}
		return Param;
	}

	/**
	 * 转化字符串编码格式
	 * 
	 * @param s1
	 *          原编码
	 * @param s3
	 *          新编码
	 * @param s
	 *          待转化字符串
	 * @return string 被转化后的字符串 在网络中传输一般都是ISO-8859-1编码
	 */
	public static String BytestoBytes(String s, String s1, String s3) {
		if (s == null) {
			return s;
		}
		String s2 = "";
		try {
			s2 = new String(s.getBytes(s1), s3);
		} catch (IOException ioexception) {
			s2 = s;
			logger.error("BytestoBytes Encoding Failer: str=".concat(String.valueOf(String.valueOf(s))));
		}
		return s2;
	}

	/**
	 * 转化字符串编码格式从GBK到ISO
	 * 
	 * @param srcString
	 *          原串
	 * @return 新串
	 */
	public static String GBKtoISO(String srcString) {
		return Func2.BytestoBytes(srcString, "GBK", "ISO-8859-1");
	}

	/**
	 * 转化字符串编码格式从iso-8859-1到GBK
	 * 
	 * @param srcString
	 *          原串
	 * @return 新串
	 */
	public static String ISOtoGBK(String srcString) {
		return Func2.BytestoBytes(srcString, "ISO-8859-1", "GBK");
	}

	public static String UTF8toISO(String srcString) {
		return Func2.BytestoBytes(srcString, "UTF-8", "ISO-8859-1");
	}

	public static String ISOtoUTF8(String srcString) {
		return Func2.BytestoBytes(srcString, "ISO-8859-1", "UTF-8");
	}

	public static String GBKtoUTF8(String srcString) {
		return Func2.BytestoBytes(srcString, "GBK", "UTF-8");
	}

	public static String UTF8toGBK(String srcString) {
		return Func2.BytestoBytes(srcString, "UTF-8", "GBK");
	}

	public String loginCheckXServices(String url) {
		String returnStr = null;
		String GetUrlContent = "";

		GetUrlContent = GetUrlContent(url);
		logger.info("Login Check URL:" + url);

		if (!(GetUrlContent.indexOf("<error>") == -1)) {
			logger.error("Login Check Failure!URL:" + url);
			returnStr = "fail";
		} else {

			try {
				Document document = DocumentHelper.parseText(GetUrlContent);
				// 取得根结点
				Element user_auth = document.getRootElement();
				// 取得set_number节点
				Element reply = user_auth.element("reply");
				returnStr = reply.getText();

			} catch (Exception e) {
				logger.error(e.getMessage() + "--- Parse XML error ! \n");
				// error(e.getMessage() + "--- Parse MARCXML error ! \n");
			}
		}

		if (returnStr == null) {
			returnStr = "fail";
		}

		return returnStr;
	}

	public String GetUrlContent(String Stringurl) {
		StringBuffer ReturnString = new StringBuffer("");
		try {
			URL url = new URL(Stringurl);
			InputStreamReader read = new InputStreamReader(url.openStream(), "UTF-8");
			BufferedReader reader = new BufferedReader(read);

			while (reader.ready()) {
				ReturnString.append(reader.readLine() + "\n");
			}
		} catch (Exception u8e) {
			logger.error(u8e.getMessage() + "--- GetUrlContent error ! \n");
		}
		return ReturnString.toString();

	}

	// 获取用户个人权限，判断功能代理
	public HashMap getUserAuthHashMap(String user_id, String library_id, String adm_library) {
		user_id = ADD_BLANK_TO_STRING(user_id, 10);// 10位
		// 变量初始化
		HashMap docHashMap = new HashMap();
		String strSql = "select Z66_FUNCTION_PROXY from " + adm_library + ".Z66 " + " where Z66_REC_KEY like '" + user_id
				+ "'";

		String strSql2 = "";

		Map user_z66 = MyDBManagerBean.searchToMap(strSql);
		String Z66_FUNCTION_PROXY = "";

		if (!(user_z66 == null)) {// 有功能代理
			Z66_FUNCTION_PROXY = getDisplayString(user_z66.get("Z66_FUNCTION_PROXY"));
			if (!Z66_FUNCTION_PROXY.equals("")) {
				Z66_FUNCTION_PROXY = ADD_BLANK_TO_STRING(Z66_FUNCTION_PROXY, 10);
				strSql2 = "select * from " + adm_library + ".Z67 " + " where Z67_REC_KEY like '" + Z66_FUNCTION_PROXY;
				strSql2 += "%' and Z67_FUNC='LCL-WEB' and Z67_LIBRARY='" + library_id + "'";
			} else {
				strSql2 = "select * from " + adm_library + ".Z67 " + " where Z67_REC_KEY like '" + user_id;
				strSql2 += "%' and Z67_FUNC='LCL-WEB' and Z67_LIBRARY='" + library_id + "'";
			}

		} else {
			strSql2 = "select * from " + adm_library + ".Z67 " + " where Z67_REC_KEY like '" + user_id;
			strSql2 += "%' and Z67_FUNC='LCL-WEB' and Z67_LIBRARY='" + library_id + "'";
		}

		ArrayList result = MyDBManagerBean.searchToMapList(strSql2);
		Iterator iterator = result.iterator();
		while (iterator.hasNext()) {
			Map rs1 = (Map) iterator.next();
			docHashMap.put(getDisplayString(rs1.get("Z67_SUB_FUNC")), getDisplayString(rs1.get("Z67_PERMISSION_FLAG")));
		}
		return docHashMap;

	}

	// 获取机构代码
	public String getInstitutionCodeSelect(String library_id, String institution_id) {
		String returnStr = "";
		String strSql = null;

		returnStr += "<select name=\"institution_code\"  size=\"1\">\n";

		if (institution_id.equals("OLCC")) {
			strSql = "select Z124_REC_KEY,Z124_CAMPUS_NAME from " + library_id + ".Z124";
		} else {
			strSql = "select Z124_REC_KEY,Z124_CAMPUS_NAME from " + library_id + ".Z124 " + " where Z124_REC_KEY = '"
					+ institution_id + "'";
		}
		strSql += " order by Z124_SORT_KEY";

		ArrayList result = MyDBManagerBean.searchToMapList(strSql);
		Iterator iterator = result.iterator();
		while (iterator.hasNext()) {
			Map rs1 = (Map) iterator.next();
			returnStr += "  <option value=\"" + getDisplayString(rs1.get("Z124_REC_KEY")) + "\">\n";
			returnStr += getDisplayString(rs1.get("Z124_REC_KEY")) + " &nbsp;&nbsp;&nbsp;&nbsp; "
					+ getDisplayString(rs1.get("Z124_CAMPUS_NAME")) + "\n";
			returnStr += "</option>\n";

		}

		returnStr += "</select>\n";
		return returnStr;
	}

	// 获取Z100_SUMMARY_PARAMS
	public String getZ100_SUMMARY_PARAMS(int Z100_START_DATE, String Z100_LOG_FILE, String adm_library,
			String update_database) {
		String returnStr = "";
		returnStr += " <tr>\n";
		returnStr += " <td align=\"left\">\n";

		if (update_database.equals("Y")) {
			returnStr += " &nbsp;&nbsp;<span class=\"text_blue\">[导入报告摘要]&nbsp;&nbsp;<span class=\"text_red\">正式导入</span></span>\n";
		} else {
			returnStr += " &nbsp;&nbsp;<span class=\"text_blue\">[导入报告摘要]&nbsp;&nbsp;<span class=\"text_red\">未正式导入</span></span>\n";
		}

		returnStr += " </td>\n";
		returnStr += " </tr>\n";

		String strSql = null;
		strSql = "select * from " + adm_library + ".Z100 ";
		strSql += " where Z100_START_DATE = " + Z100_START_DATE + " and Z100_LOG_FILE='" + Z100_LOG_FILE + "'";

		Map z100 = MyDBManagerBean.searchToMap(strSql);

		String Z100_SUMMARY_PARAMS = "";
		if (!(z100 == null)) {
			Z100_SUMMARY_PARAMS = getDisplayString(z100.get("Z100_SUMMARY_PARAMS"), false);
			if (Z100_SUMMARY_PARAMS.length() > 450) {
				returnStr += " <tr>\n";
				returnStr += " <td  align=\"center\">\n";
				returnStr += " <table width=\"96%\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\" align=\"left\">\n";
				returnStr += " <tr>\n";
				returnStr += " <td  align=\"left\">\n&nbsp;&nbsp;";

				returnStr += "读取的书目记录数:" + Integer.parseInt(Z100_SUMMARY_PARAMS.substring(20, 29));
				returnStr += "</td> </tr>\n";
				returnStr += " <tr>\n";
				returnStr += " <td  align=\"left\">\n&nbsp;&nbsp;";
				returnStr += "不匹配的书目记录数:" + Integer.parseInt(Z100_SUMMARY_PARAMS.substring(70, 79)) + ";&nbsp;&nbsp;";
				returnStr += "唯一匹配的书目记录数:" + Integer.parseInt(Z100_SUMMARY_PARAMS.substring(120, 129)) + ";&nbsp;&nbsp;";
				returnStr += "多匹配的书目记录数:" + Integer.parseInt(Z100_SUMMARY_PARAMS.substring(170, 179)) + ";&nbsp;&nbsp;";
				returnStr += "</td> </tr>\n";
				returnStr += " <tr>\n";
				returnStr += " <td  align=\"left\">\n&nbsp;&nbsp;";
				returnStr += "已创建的书目记录数:" + Integer.parseInt(Z100_SUMMARY_PARAMS.substring(320, 329)) + ";&nbsp;&nbsp;";
				returnStr += "已创建的馆藏记录数:" + Integer.parseInt(Z100_SUMMARY_PARAMS.substring(370, 379)) + ";&nbsp;&nbsp;";
				returnStr += "未成功创建的馆藏记录数:" + Integer.parseInt(Z100_SUMMARY_PARAMS.substring(420, 429)) + ";&nbsp;&nbsp;";
				returnStr += "失效的书目记录数:" + Integer.parseInt(Z100_SUMMARY_PARAMS.substring(220, 229)) + ";&nbsp;&nbsp;";
				returnStr += "已删除的书目记录数:" + Integer.parseInt(Z100_SUMMARY_PARAMS.substring(270, 279)) + ";&nbsp;&nbsp;";
				returnStr += "</td> </tr>\n";
				returnStr += " <tr>\n";
				returnStr += " </table></td></tr>\n";
			}
		}

		return returnStr;
	}

	// aleph的权限，如果设置了，如某个子功能 全部允许；再在下面某个细项 拒绝；则细项拒绝，其它允许
	public boolean getUserAuth(String user_id, String sub_func, HashMap UserAuthHashMap) {
		boolean returnFlag = false;
		user_id = ADD_BLANK_TO_STRING(user_id, 10);// 10位

		if (UserAuthHashMap.get(sub_func) != null) {
			if (UserAuthHashMap.get(sub_func).equals("Y")) {
				returnFlag = true;
			} else {
				returnFlag = false;
			}
		} else {
			if (UserAuthHashMap.get("GLOBAL") != null) {
				if (UserAuthHashMap.get("GLOBAL").equals("Y")) {
					returnFlag = true;
				} else {
					returnFlag = false;
				}
			} else {
				returnFlag = false;
			}
		}

		return returnFlag;
	}

	// ***************************************************************************
	/**
	 * 格式化字串: 给字串加空格,后面不足补空格 ADD_BLANK_TO_STRING
	 * 
	 * @param s
	 *          字串
	 * @param blank_number
	 *          位数 总共位数,包括空格 ALEPH 0001
	 * @return String
	 */
	// ***************************************************************************
	public String ADD_BLANK_TO_STRING(String s, int blank_number) {
		String returen_Str = "";
		String tmpStr = "";
		StringBuffer tmpStr1 = new StringBuffer("");
		tmpStr = s;
		for (int i = 0; i < (blank_number - tmpStr.length()); i++) {
			// tmpStr1 = " " + tmpStr1;
			tmpStr1.append(" ");
		}
		returen_Str = tmpStr + tmpStr1.toString();

		return returen_Str;
	}

	// ***************************************************************************
	/**
	 * 格式化字串(UTF8): 给字串加空格,后面不足补空格 ADD_BLANK_TO_STRING
	 * 
	 * @param s
	 *          字串
	 * @param blank_number
	 *          位数 总共位数,包括空格 ALEPH 0001
	 * @return String
	 */
	// ***************************************************************************
	public String ADD_BLANK_TO_STRING(String s, int blank_number, String byte_Type) {
		String returen_Str = "";
		StringBuffer tmpStr1 = new StringBuffer("");
		int strLength = 0;
		strLength = ByteLength(s, byte_Type);

		for (int i = 0; i < (blank_number - strLength); i++) {
			// tmpStr1 = " " + tmpStr1;
			tmpStr1.append(" ");
		}
		returen_Str = s + tmpStr1.toString();

		return returen_Str;
	}

	// 根据字节数来计算一个字符串的长度
	public int ByteLength(String text, String byte_Type) {

		byte temp[];
		int ReturnLength = 0;

		try {
			temp = text.getBytes(byte_Type);
			ReturnLength = temp.length;
		} catch (Exception e) {
			System.out.println(e.toString());
		}

		return ReturnLength;
	}

	/**
	 * 该函数获取LCL_Param
	 * 
	 * @param LCL_Param_Name
	 *          参数名称 如 ACQ_ORDER_METHOD
	 * @param ADMName
	 *          ADM名称
	 * @return 字符串数组 Sub_Library[i][0] getName Sub_Library[i][1] getValue
	 */
	public String[][] get_LCL_Param(String FilePathName, String LCL_Param_Name) {

		ArrayList matchList = new ArrayList();
		java.io.File ThisFile = new java.io.File(FilePathName);

		// 读文件获取需要的行
		try {
			String lineStr = null;
			InputStreamReader read = new InputStreamReader(new FileInputStream(ThisFile), "GBK");
			BufferedReader br = new BufferedReader(read);
			while ((lineStr = br.readLine()) != null) {
				lineStr = lineStr.trim();
				// LogInfo(lineStr+"---------\n");

				// 注释行
				if (lineStr.length() > 1) {
					if ((lineStr.substring(0, 1)).equals("!")) {
						continue;
					}
				}

				if (lineStr.length() > 25) {
					if (((lineStr.substring(0, 25)).trim()).equals(LCL_Param_Name)) {
						matchList.add(lineStr);
						// LogInfo(lineStr);
					}
				}
				/*
				 * if(lineStr.indexOf(ADMName)!=-1){ matchList.add(lineStr);
				 * LogInfo(lineStr); }
				 */
			}
			br.close();
			read.close();
		} catch (Exception e) {
			logger.error("获取LCL_Param时，读文件出错！");
		}

		int resultSize = matchList.size();
		String[] result = new String[resultSize];
		matchList.subList(0, resultSize).toArray(result);
		// return (String[]) matchList.subList(0, resultSize).toArray(result);

		String[][] LCL_Param = new String[resultSize][2];
		for (int i = 0; i < resultSize; i++) {
			// getName
			LCL_Param[i][0] = (SubStringByte(result[i], 27, 77)).trim();
			// getValue
			LCL_Param[i][1] = (SubStringByte(result[i], 78)).trim();
			// LogInfo("<br>"+LCL_Param[i][0]+"---------"+LCL_Param[i][1]+"\n<br>");

		}
		return (String[][]) LCL_Param;

	}

	public String[][] get_tab_formats(String tab_formats_file) {

		ArrayList matchList = new ArrayList();
		java.io.File ThisFile = new java.io.File(tab_formats_file);

		// 读文件获取需要的行
		try {
			String lineStr = null;
			InputStreamReader read = new InputStreamReader(new FileInputStream(ThisFile), "GBK");
			BufferedReader br = new BufferedReader(read);
			while ((lineStr = br.readLine()) != null) {
				lineStr = lineStr.trim();
				// 注释行
				if (lineStr.length() > 2) {
					if ((lineStr.substring(0, 1)).equals("!") || (lineStr.substring(0, 2)).equals("00")
							|| (lineStr.substring(0, 2)).equals("99")) {
						continue;
					}
				}

				if (lineStr.length() > 2) {
					matchList.add(lineStr);
				}
				/*
				 * if(lineStr.indexOf(ADMName)!=-1){ matchList.add(lineStr);
				 * LogInfo(lineStr); }
				 */
			}
			br.close();
			read.close();
		} catch (Exception e) {
			logger.error("Get file tab_formats error!");
		}

		int resultSize = matchList.size();
		String[] result = new String[resultSize];
		matchList.subList(0, resultSize).toArray(result);
		// return (String[]) matchList.subList(0, resultSize).toArray(result);

		String[][] LCL_Param = new String[resultSize][2];
		for (int i = 0; i < resultSize; i++) {
			// getName
			LCL_Param[i][0] = (SubStringByte(result[i], 0, 2)).trim();
			// getValue
			LCL_Param[i][1] = (SubStringByte(result[i], 3)).trim();
			// LogInfo("<br>"+LCL_Param[i][0]+"---------"+LCL_Param[i][1]+"\n<br>");

		}
		return (String[][]) LCL_Param;

	}

	public String getXmlAddXslToHtml(String repFileName, String xslFileName) throws Exception {

		String xmlFileName = "";
		int pt = 0;
		pt = repFileName.lastIndexOf(".");

		if (pt != -1) {
			xmlFileName = repFileName.substring(0, pt) + ".xml";
		}

		String repFileContent = "";

		StringBuffer ReturnContent = new StringBuffer("");
		java.io.File ThisFile = new java.io.File(repFileName);
		String line = null;

		String repFile_Name = "";

		repFile_Name = ThisFile.getName();

		try {

			InputStreamReader read = new InputStreamReader(new FileInputStream(ThisFile), "UTF-8");
			BufferedReader br = new BufferedReader(read);
			while ((line = br.readLine()) != null) {
				if (line.equals("## - XML_XSL")) {
					continue;
				} else {
					ReturnContent.append(line + "\n");
				}

			}
			br.close();
			read.close();
		} catch (Exception e) {
			logger.error("读文件" + repFileName + "出错！\n");
		}

		File file = new File(xmlFileName);

		repFileContent = ReturnContent.toString();
		repFileContent = repFileContent.replace(ThisFile.getName(), file.getName());

		boolean writeFile = SetFileContent(xmlFileName, repFileContent, "UTF-8");

		StringWriter writer = new StringWriter();
		StreamResult streamResult = new StreamResult(writer);
		TransformerFactory tFactory = TransformerFactory.newInstance();
		Transformer transformer = null;
		try {
			transformer = tFactory.newTransformer(new StreamSource(xslFileName));
		} catch (TransformerConfigurationException _ex) {
			System.err.println("Error in simpleTransform1! " + _ex);

		}

		try {
			// transformer.setOutputProperty("encoding","GBK");
			// transformer.setOutputProperty(javax.xml.transform.OutputKeys.ENCODING,
			// "GBK");
			transformer.transform(new StreamSource(file), streamResult);
		} catch (TransformerException _ex) {
			System.err.println("Error in simpleTransform2! " + _ex + ":" + xmlFileName);

		}
		return ((StringWriter) streamResult.getWriter()).toString();
	}

	/**
	 * 该函数获取LCL_Param 的hashmap
	 * 
	 * @param HashMap
	 * 
	 * @param FilePathName
	 * 
	 * @return HashMap
	 */
	public HashMap getHashMap(HashMap map_hash, String FilePathName) {

		java.io.File ThisFile = new java.io.File(FilePathName);
		String map_key = null;
		String map_value = null;

		// 读文件获取需要的行
		try {
			String lineStr = null;
			InputStreamReader read = new InputStreamReader(new FileInputStream(ThisFile), "GBK");
			BufferedReader br = new BufferedReader(read);
			while ((lineStr = br.readLine()) != null) {
				lineStr = lineStr.trim();
				// LogInfo(lineStr+"---------\n");

				// 注释行
				if (lineStr.length() > 1) {
					if ((lineStr.substring(0, 1)).equals("!")) {
						continue;
					}
				}

				if (lineStr.length() > 20) {

					map_key = (SubStringByte(lineStr, 0, 20)).trim() + ":" + (SubStringByte(lineStr, 78)).trim();
					map_value = (SubStringByte(lineStr, 27, 77)).trim();
					map_hash.put(map_key, map_value);
					// map_hash.put((SubStringByte(lineStr, 0, 20)).trim() + ":", "");

				}
				/*
				 * if(lineStr.indexOf(ADMName)!=-1){ matchList.add(lineStr);
				 * LogInfo(lineStr); }
				 */
			}
			br.close();
			read.close();
		} catch (Exception e) {
			logger.error("获取LCL_Param时，读文件出错！");
		}
		return map_hash;

	}

	public String getExcelFieldName(String argString, WritableSheet ws, int j, int i) {

		if (argString == null) {
			argString = "";
		} else {
			argString = argString.trim();
		}

		if (ws != null) {

			try {
				WritableFont font1 = new WritableFont(WritableFont.createFont("SimSun"), 10, WritableFont.BOLD);
				WritableCellFormat format1 = new WritableCellFormat(font1);
				// format1.setAlignment(jxl.format.Alignment.CENTRE);
				Label labelC = new Label(j, i, argString, format1);
				// 将生成的单元格添加到工作表中
				ws.addCell(labelC);
			} catch (Exception e) {
				System.err.println(e);
			}
		}
		return argString;
	}

	public String getExcelString(String argString, WritableSheet ws, int j, int i) {
		String tmp = "";

		if (argString == null) {
			argString = "";
			tmp = argString;
		} else {
			argString = argString.trim();
			tmp = argString;
			// argString = changeToHtml(argString);
		}

		if (ws != null) {
			tmp = replaceInString(tmp, "<br>", "  ");
			Label labelC = new Label(j, i, tmp);
			try {
				// 将生成的单元格添加到工作表中
				ws.addCell(labelC);
			} catch (Exception e) {
				System.err.println(e);
			}
		}
		return argString;
	}

	public String getExcelNumber(String argString, WritableSheet ws, int j, int i) {

		if (argString == null) {
			argString = "";
		} else {
			argString = argString.trim();
			// argString = changeToHtml(argString);
		}

		if (ws != null) {
			try {
				if (isInteger(argString) == true && isDouble(argString) == false) {
					jxl.write.Number number = new jxl.write.Number(j, i, Integer.parseInt(argString));
					// 将生成的单元格添加到工作表中
					ws.addCell(number);
				} else if (isDouble(argString) == true) {

					jxl.write.Number number = new jxl.write.Number(j, i, Double.parseDouble(argString));
					ws.addCell(number);
				} else {
					Label labelC = new Label(j, i, argString);
					ws.addCell(labelC);
				}
			} catch (Exception e) {
				System.err.println(e);
			}
		}
		return argString;
	}

	/**
	 * 判断字符串是否是整数
	 */
	public static boolean isInteger(String value) {
		try {
			Integer.parseInt(value);
			return true;
		} catch (NumberFormatException e) {
			return false;
		}
	}

	/**
	 * 判断字符串是否是浮点数
	 */
	public static boolean isDouble(String value) {
		try {
			Double.parseDouble(value);
			if (value.indexOf(".") != -1)
				return true;
			return false;
		} catch (NumberFormatException e) {
			return false;
		}
	}

	/**
	 * 判断字符串是否是数字
	 */
	public static boolean isNumber(String value) {
		return isInteger(value) || isDouble(value);
	}

	/**
	 * 判断字符串是否是数字
	 */
	public static boolean isChinese(String value) {
		Pattern pattern = Pattern.compile("[\u4e00-\u9fa5]");
		Matcher matcher = pattern.matcher(value);
		return matcher.find();
	}

}
